# -*- coding: utf-8 -*-
#
# Author:: hanjunfeng
# Date:: 2021/1/29
import os
import pathlib
import sys
from pathlib import Path


def with_add_suffix_before_extension(filename, suffix="_tmp"):
    '''
    filename:文件的绝对路径
    '''
    p = Path(filename)
    target_name = p.with_name(p.with_suffix("").name + suffix + p.suffix)
    return target_name


def rename_add_suffix_before_extension(filename, suffix="_tmp"):
    '''
    filename:文件的绝对路径
    '''
    p = Path(filename)
    target_name = p.with_name(p.with_suffix("").name + suffix + p.suffix)
    p.rename(target_name)


def format_path(path=""):
    p = Path(path)
    return str(p)


def get_filename():
    p = Path(sys.argv[0])
    return p.name


def get_filename_pure():
    p = Path(get_filename())
    return str(p.with_suffix(""))


if __name__ == "__main__":
    def forma_path_test():
        p = "\common\lib"
        res = format_path(p)
        print(res)


    def test_get_filename_pure():
        res = get_filename_pure()
        print(type(res))


    def test_get_filename():
        res = get_filename()
        print(type(res))


    test_get_filename()
